home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / mnp_c.zip / MNPMISC.C < prev    next >
Text File  |  1990-05-16  |  3KB  |  163 lines

  1. /*=============================================================================
  2.  
  3.                      The Microcom MNP Library
  4.                     (Microsoft C Version)
  5.  
  6. -------------------------------------------------------------------------------
  7.  
  8.            MNPMISC - Miscellaneous MNP Support Routines
  9.  
  10. ==========================================================================*/
  11.  
  12. /* Header files */
  13. #include <mnpdat.h>
  14.  
  15. /***************************************************************************
  16. *
  17. *    BUFFER MANAGEMENT - INITIALIZE THE ARRAY OF STRUCTURES CONTROLLING
  18. *                THE BUFFERS
  19. *
  20. *    Synopsis:    init_blst(buff, len)
  21. *            struct buffer *b_struct;
  22. *            int len;
  23. *            char *buff;
  24. *
  25. *            returns:
  26. *
  27. ****************************************************************************/
  28.  
  29.  
  30. SIGN_16 init_blst(b_struct, len, buff)
  31.  
  32. struct BUFFER *b_struct;
  33. USIGN_16 len;
  34. USIGN_8 *buff;
  35.  
  36. {
  37. register USIGN_16 i;
  38.  
  39. for (i=0; i < b_struct->num - 1;)
  40.     {
  41.     b_struct->list[i].mark = 0;
  42.     b_struct->list[i].bptr = buff + (len * i);
  43.     b_struct->list[i].next_b = &b_struct->list[++i];
  44.     }
  45. b_struct->list[i].mark = 0;
  46. b_struct->list[i].bptr = buff + (len * i);
  47. b_struct->free = b_struct->list[i].next_b = b_struct->list;
  48.  
  49. b_struct->used = 0;
  50. b_struct->used_lst = 0;
  51.  
  52. return;
  53. }
  54.  
  55. /***************************************************************************
  56. *
  57. *    BUFFER MANAGEMENT - GET POINTER TO A FREE BUFFER
  58. *
  59. *    Synopsis:
  60. *
  61. *
  62. *            returns: SUCCESS
  63. *                 FAILURE - no free buffer
  64. *
  65. ***************************************************************************/
  66.  
  67. SIGN_16 get_b(b_struct, bl_struct)
  68.  
  69. struct BUFFER *b_struct;
  70. struct BLST **bl_struct;
  71.  
  72. {
  73. if ((USIGN_16)(*bl_struct = b_struct->free))
  74.     {
  75.     (*bl_struct)->mark = 1;
  76.     if (++b_struct->used == b_struct->num)
  77.         b_struct->free = 0;
  78.     else
  79.         b_struct->free = b_struct->free->next_b;
  80.     return (SUCCESS);
  81.     }
  82. else
  83.     return (FAILURE);
  84. }
  85.  
  86. /***************************************************************************
  87. *
  88. *    BUFFER MANAGEMENT - RETURN A BUFFER TO THE FREE POOL
  89. *
  90. *    Synopsis:
  91. *
  92. *
  93. *
  94. *            returns: 0: success
  95. *
  96. ****************************************************************************/
  97.  
  98.  
  99. SIGN_16 ret_b(b_struct, bl_struct)
  100.  
  101. struct BUFFER *b_struct;
  102. struct BLST *bl_struct;
  103.  
  104. {
  105. if (bl_struct->mark)
  106.     {
  107.     bl_struct->mark = 0;
  108.     b_struct->used--;
  109.     if ((USIGN_16)b_struct->free == 0)
  110.         b_struct->free = bl_struct;
  111.     }
  112. return (SUCCESS);
  113. }
  114.  
  115.  
  116.  
  117. /***************************************************************************
  118. *
  119. *    BUFFER MANAGEMENT - RESET THE WHOLE BUFFER POOL TO BE FREE
  120. *
  121. *    Synopsis:
  122. *
  123. *
  124. *
  125. ****************************************************************************/
  126.  
  127. void reset_blst(b_struct)
  128.  
  129. struct BUFFER *b_struct;
  130.  
  131. {
  132. register USIGN_16 i;
  133.  
  134. for (i=0; i < b_struct->num; i++)
  135.     b_struct->list[i].mark = b_struct->list[i].len = 0;  /* mark all as free */
  136.  
  137. b_struct->used = 0;
  138. b_struct->used_lst = 0;
  139. b_struct->free = b_struct->list;
  140. }
  141.  
  142.  
  143. /***************************************************************************
  144. *
  145. *
  146. *
  147. *
  148. ****************************************************************************/
  149.  
  150. USIGN_16 min (a, b)
  151.  
  152. USIGN_16  a, b;
  153. {
  154. return ((a) < (b) ? (a): (b));
  155. }
  156.  
  157. USIGN_16 max (a, b)
  158.  
  159. USIGN_16 a, b;
  160. {
  161. return ((a) > (b) ? (a): (b));
  162. }
  163.